<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

use yii\helpers\Json;

/* ===================== 动态控件操作项 ===================== */

/** @var \yii\web\View $this View实例 */
/* @var array $formDynamicControl 表单动态控件选项 */
?>
<script>
    /**
     * 删除一行
     * @param id 动态控件ID
     * @param index 数据索引
     */
    $scope.actionDeleteDynamicControl = function (id, index) {
        switch (id) {
<?php foreach ($formDynamicControl as $item): ?>
            case "<?= $item['__id'] ?>":
                $scope.<?= $item['__scope'] ?>.splice(index, 1);
                break;
<?php endforeach; ?>
        }
    };

    /**
     * 新增一行
     * @param id 动态控件ID
     */
    $scope.actionAddDynamicControl = function (id) {
        var valTpl;
        switch (id) {
<?php foreach ($formDynamicControl as $item): ?>
            case "<?= $item['__id'] ?>":
                valTpl = <?= Json::encode($item['__valTpl']) ?>;
                $scope.<?= $item['__scope'] ?>.push(valTpl);
                break;
<?php endforeach; ?>
        }
    };
</script>